www.gusucode.com > VC++ 仿SQLServer企业管理器的SQL客户端工具-源码程序 > VC++ 仿SQLServer企业管理器的SQL客户端工具-源码程序/code/BaseListCtrl.cpp

    // BaseListCtrl.cpp : implementation file
// Download by http://www.NewXing.com

#include "stdafx.h"
#include "frontTool.h"
#include "BaseListCtrl.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CBaseListCtrl

CBaseListCtrl::CBaseListCtrl()
{
	m_iDefW=80;
}

CBaseListCtrl::~CBaseListCtrl()
{
}

void CBaseListCtrl::ResetColInfo(char* pdszInfo,int *piWidth)
{
	//DeleteAllItems();
	CStringArray arr;
	int i=0;
	while(DeleteColumn(0));
	CString szCol;
	int iPos=0;
	i=0;
	try
	{
	while(1)
	{
		szCol=pdszInfo+i;
		i+=szCol.GetLength();
		i++;
		int iWidth=(piWidth)?piWidth[iPos]:-1;
		//InsertColumn(iPos,szCol,LVCFMT_LEFT,iWidth,iPos);
		arr.Add(szCol);
		iPos++;
		if(pdszInfo[i+1]=='\0')
			break;
	}
	}
	catch(void* pE)
	{
		TRACE("error in ResetColInfo\n");
	}
	ResetColInfo(arr,piWidth);
	arr.RemoveAll();
}
void CBaseListCtrl::ResetColInfo(CStringArray &arrName,int *piWidth)
{
	DeleteAllItems();
	int i=0;
	while(DeleteColumn(0));
	CString szCol;
	for(i=0;i<arrName.GetUpperBound()+1;i++)
	{
		szCol=arrName.GetAt(i);
		int iWidth=(piWidth)?piWidth[i]:m_iDefW;
		InsertColumn(i,szCol,LVCFMT_LEFT,iWidth,i);
	}
}

BOOL CBaseListCtrl::ResetColInfo(CFTDB* pDB)
{
	CStringArray arrRes;
	pDB->GenerateDescString(arrRes);
	int* piW=new int[arrRes.GetUpperBound()+1];
	for(int i=0;i<arrRes.GetUpperBound()+1;i++)
	{
		piW[i]=pDB->m_arrColDataPrecision[i]*6;
		if(piW[i]<40)
			piW[i]=40;
		if(piW[i]>150)
			piW[i]=150;
	}
	ResetColInfo(arrRes,piW);
	delete piW;
	return TRUE;
}

BEGIN_MESSAGE_MAP(CBaseListCtrl, CListCtrl)
	//{{AFX_MSG_MAP(CBaseListCtrl)
	ON_WM_CREATE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBaseListCtrl message handlers

int CBaseListCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CListCtrl::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	DWORD dwStyle = SendMessage(LVM_GETEXTENDEDLISTVIEWSTYLE);
	dwStyle |= LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES ;
	SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0, (LPARAM)dwStyle);
	return 0;
}

BOOL CBaseListCtrl::PreCreateWindow(CREATESTRUCT& cs) 
{
	cs.style |= LVS_REPORT;
	//cs.style |= WS_BORDER;
	return CListCtrl::PreCreateWindow(cs);
}